/**
 * 
 */
package dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import utils.Const;
import utils.StatusType;

import com.j256.ormlite.dao.Dao;
import database.DatabaseHelper;
import entity.Plan;

/**
 * @author Hung
 *
 */
public class PlanDAO {
	
	private Dao<Plan, Integer> dao = null;
	
	public PlanDAO(DatabaseHelper helper) throws Exception {
		dao = helper.getPlanDao();
		if (dao == null)
			throw new Exception(Const.NULL_DAO_ERROR);
	}
	
	public int createPlan(Plan plan) throws SQLException {
		return dao.create(plan);
	}
	
	public int updatePlan(Plan plan) throws SQLException {
		return dao.update(plan);
	}
	
	public int deletePlan(Plan plan) throws SQLException {
		return dao.delete(plan);
	}
	
	public Plan getPlanById(int id) throws SQLException {
		return dao.queryForId(id);
	}
	
	public List<Plan> getListPlanUndone() throws SQLException {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("status", StatusType.UNDONE);
		
		return dao.queryForFieldValues(map);
	}
	
	public List<Plan> getAllPlan() throws SQLException {
		return dao.queryForAll();
	}
}
